﻿<!-- ReSharper disable InconsistentNaming -->
<Window xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        x:Class="WSManager.Wpf.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:loc="clr-namespace:WSManager.Wpf"
        Title="MainWindow" Height="500" Width="525" x:Name="mainWindow" Closing="mainWindow_Closing" >
    <Window.DataContext>
        <loc:ViewModel x:Name="viewModel"></loc:ViewModel>
    </Window.DataContext>
    
    <Grid Margin="10">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <StackPanel Orientation="Horizontal">
                <Menu IsMainMenu="True">
                    <MenuItem Header="Webs">
                        <MenuItem Header="New" Command="{Binding NewWebCommand}">

                        </MenuItem>
                        <MenuItem Header="Remove" Command="{Binding RemoveWebCommand}">

                        </MenuItem>
                        <MenuItem Header="Save" Command="{Binding SaveCommand}"></MenuItem>
                        <MenuItem Header="Discard changes" Command="{Binding DiscardChangesCommand}"></MenuItem>
                        <MenuItem Header="Save Automaticaly" IsCheckable="True" IsChecked="{Binding AutoSave, Mode=TwoWay}"></MenuItem>
                        <MenuItem Header="EditArticleMetadataDefinitions" Command="{Binding EditMetaDefinitions}"></MenuItem>
                    </MenuItem>
                </Menu>
                <ComboBox x:Name="websComboBox" HorizontalAlignment="Right" VerticalAlignment="Top" Width="Auto" MinWidth="100" MaxWidth="250" Height="Auto"
                   ItemsSource="{Binding Webs}" DisplayMemberPath="Name" SelectedValuePath="Name" SelectedValue="{Binding SelectedWebName, Mode=TwoWay}"
                      Grid.Row="0" Margin="5,0">
                </ComboBox>
            </StackPanel>
            <TabControl x:Name="tabs" Margin="15" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="Auto" Grid.Row="1">
                <TabItem Header="Articles">

                    <Grid DataContext="{Binding SelectedWeb}">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <ScrollViewer Grid.Row="0">
                            <ItemsControl x:Name="articles" ItemsSource="{Binding Articles}" ScrollViewer.CanContentScroll="true" ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.VerticalScrollBarVisibility="Visible">
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <Border BorderBrush="#FF767676" BorderThickness="0, 0, 0, 2">
                                            <StackPanel>
                                                <TextBlock FontWeight="Bold" FontSize="17" Text="{Binding Name}"></TextBlock>
                                                <TextBlock FontSize="10" Text="{Binding Description, Converter={StaticResource stringShortener}}"></TextBlock>
                                                <StackPanel Orientation="Horizontal">
                                                    <CheckBox IsChecked="{Binding Checked}"></CheckBox>
                                                    <Button Command="{Binding EditArticle}" Style="{StaticResource smallButton}">Edit</Button>
                                                </StackPanel>
                                            </StackPanel>
                                        </Border>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                                <ItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <StackPanel></StackPanel>
                                    </ItemsPanelTemplate>
                                </ItemsControl.ItemsPanel>
                            </ItemsControl>
                        </ScrollViewer>
                        <StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Right">
                            <Button Command="{Binding NewArticle}" HorizontalAlignment="Right" Style="{StaticResource smallButton}">New Article</Button>
                            <Button Command="{Binding RemoveArticlesCommand}" HorizontalAlignment="Right" Style="{StaticResource smallButton}" CommandParameter="{Binding ElementName=articles, Path=ItemsSource}">Remove Articles</Button>
                        </StackPanel>
                    </Grid>
                </TabItem>
                <TabItem Header="Categories">
                    <Grid DataContext="{Binding SelectedWeb}">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <ScrollViewer Grid.Row="0">
                            <TreeView ItemsSource="{Binding Categories}" ScrollViewer.CanContentScroll="True" x:Name="categoryTree">
                                <TreeView.ItemContainerStyle>
                                    <Style>
                                        <Setter Property="TreeViewItem.IsExpanded" Value="True"/>
                                        <!--<Style.Triggers>
                                            <DataTrigger Binding="{Binding Path=Type}" Value="menu">
                                                <Setter Property="TreeViewItem.IsSelected" Value="True"/>
                                            </DataTrigger>
                                        </Style.Triggers>-->
                                    </Style>
                                </TreeView.ItemContainerStyle>

                                <TreeView.ItemTemplate>
                                    <HierarchicalDataTemplate ItemsSource="{Binding Subcategories}">
                                        <TextBlock TextWrapping="WrapWithOverflow">
                                            <CheckBox IsChecked="{Binding Checked, Mode=TwoWay}" ></CheckBox>
                                            <TextBlock Text="{Binding Name}" ToolTip="{Binding Description}" FontSize="17" FontWeight="Bold" />
                                            <TextBlock FontSize="12" FontStyle="Italic">('<TextBlock Text="{Binding Description}"/>')</TextBlock>
                                        </TextBlock>
                                    </HierarchicalDataTemplate>
                                </TreeView.ItemTemplate>
                            </TreeView>
                        </ScrollViewer>
                        <StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Right">
                            <Button Command="{Binding NewCategoryCommand}" CommandParameter="{Binding ElementName=categoryTree, Path=SelectedItem}" Style="{StaticResource smallButton}">New category</Button>
                            <Button Command="{Binding RemoveCategoriesCommand}" CommandParameter="{Binding ElementName=categoryTree, Path=SelectedItem}" Style="{StaticResource smallButton}">Remove categories</Button>
                        </StackPanel>
                    </Grid>
                </TabItem>
            </TabControl>
        </Grid>
    </Grid>
</Window>

<!-- ReSharper restore InconsistentNaming -->
